﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DaFuWon
{
    public partial class Form1 : Form
    {
        private int charactorID = 0;
        private int cellnum = 9999;
        private int[] charcellnum = new int[] { 0, 26, 52, 78 };
        private int[,] pGMI = new int[,] {  {- 502, - 454},  // panelGamingMapInside
                                            {- 712, - 454},
                                            {- 817, - 454},
                                            {- 922, - 454},
                                            {-1027, - 454},
                                            {-1132, - 454},
                                            {-1237, - 454},
                                            {-1342, - 454},  // 正右  

                                            {-1342, - 538},  // 8
                                            {-1342, - 664},
                                            {-1342, - 769},
                                            {-1342, - 895},
                                            {-1342, -1000},
                                            {-1342, -1084},  // 右下

                                            {-1237, -1084},  // 14
                                            {-1132, -1084},
                                            {-1027, -1084},
                                            {- 922, -1084},
                                            {- 817, -1084},
                                            {- 712, -1084},
                                            {- 607, -1084},
                                            {- 523, -1084},  // 正下

                                            {- 523, -1000},  // 22
                                            {- 523, - 895},
                                            {- 523, - 769},
                                            {- 523, - 664},
                                            {- 523, - 412},  // 桃子
                                            {- 523, - 202},
                                            {- 523, -  97},
                                            {- 523,    29},
                                            {- 523,   134},
                                            {- 523,   260},  // 正上

                                            {- 607,   260},  // 32
                                            {- 712,   260},
                                            {- 817,   260},
                                            {- 922,   260},
                                            {-1027,   260},
                                            {-1132,   260},
                                            {-1237,   260},
                                            {-1342,   260},  // 右上

                                            {-1342,   134},  // 40
                                            {-1342,    29},
                                            {-1342, -  97},
                                            {-1342, - 202},
                                            {-1342, - 307},
                                            {-1342, - 412},  // 正右

                                            {-1237, - 412},  // 46
                                            {-1132, - 412},
                                            {-1027, - 412},
                                            {- 922, - 412},
                                            {- 817, - 412},
                                            {- 712, - 412},
                                            {- 502, - 412},  // 桃子
                                            {- 292, - 412},  // 53
                                            {- 187, - 412},
                                            {-  82, - 412},
                                            {   23, - 412},
                                            {  128, - 412},
                                            {  233, - 412},
                                            {  338, - 412},  // 正左

                                            {  338, - 307},  // 60
                                            {  338, - 202},
                                            {  338, -  97},
                                            {  338,    29},
                                            {  338,   134},
                                            {  338,   260},  // 左上

                                            {  233,   260},  // 66
                                            {  128,   260},
                                            {   23,   260},
                                            {-  82,   260},
                                            {- 187,   260},
                                            {- 292,   260},
                                            {- 397,   260},
                                            {- 481,   260},  // 正上

                                            {- 481,   134},  // 74
                                            {- 481,    29},
                                            {- 481, -  97},
                                            {- 481, - 202},
                                            {- 481, - 433},  // 桃子
                                            {- 481, - 664},
                                            {- 481, - 769},
                                            {- 481, - 895},
                                            {- 481, -1000},
                                            {- 481, -1084},  // 正下

                                            {- 397, -1084},  // 84
                                            {- 292, -1084},
                                            {- 187, -1084},
                                            {-  82, -1084},
                                            {   23, -1084},
                                            {  128, -1084},
                                            {  233, -1084},
                                            {  338, -1084},  // 左下

                                            {  338, -1000},  // 92
                                            {  338, - 895},
                                            {  338, - 769},
                                            {  338, - 664},
                                            {  338, - 538},
                                            {  338, - 454},  // 正左

                                            {  233, - 454},  // 98
                                            {  128, - 454},
                                            {   23, - 454},
                                            {-  82, - 454},
                                            {- 187, - 454},
                                            {- 292, - 454},
                                            {- 502, - 454},  // 原點 104
                                        };

        public Form1()
        {
            InitializeComponent();

            panelStart.Visible = true;
            panelCharChoose.Visible = false;
            panelGaming.Visible = false;

            pictureBoxGamingCharStateBG.Controls.Add(labelGamingCharStateName);
            pictureBoxGamingCharStateBG.Controls.Add(labelGamingCharStateMoney);
            pictureBoxGamingCellStateBG.Controls.Add(labelcellstatus);
            pictureBoxGamingCellStateBG.Controls.Add(labelcelltype);
            pictureBoxGamingCellStateBG.Controls.Add(labelOwner);
            pictureBoxGamingCellStateBG.Controls.Add(labelOwnerName);

            DebugDice.Size = new System.Drawing.Size(0, 0);
            DebugDice.Text  = panelGamingMapInside.Location.X.ToString();
            DebugDice.Text += "\n";
            DebugDice.Text += panelGamingMapInside.Location.Y.ToString();
            DebugDice.Refresh();
        }

        private void buttonPlay_Click(object sender, EventArgs e)
        {
            panelCharChoose.Visible = true;
            panelStart.Visible = false;
        }

        private void buttonCharChooseEnter_Click(object sender, EventArgs e)
        {
            panelGaming.Visible = true;
            panelCharChoose.Visible = false;

            Gaming();
        }

        //用來避免人物選擇重覆 ============================================== By 毛毛
        String tmp1, tmp2, tmp3, tmp4;
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //圖片方塊顯示清單項目所選的圖片
            if (comboBoxCharChoose1.Text != "" && tmp1 != comboBoxCharChoose1.Text)//已經選過要把之前移除的項目加回來
            {
                if (tmp1 == "001")
                {
                    comboBoxCharChoose2.Items.Add(tmp1); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add(tmp1);
                    comboBoxCharChoose4.Items.Add(tmp1);
                }
                if (tmp1 == "桃太郎")
                {
                    comboBoxCharChoose2.Items.Add("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("桃太郎");
                    comboBoxCharChoose4.Items.Add("桃太郎");
                }
                if (tmp1 == "大魔王")
                {
                    comboBoxCharChoose2.Items.Add("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("大魔王");
                    comboBoxCharChoose4.Items.Add("大魔王");
                }
                if (tmp1 == "王子")
                {
                    comboBoxCharChoose2.Items.Add("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("王子");
                    comboBoxCharChoose4.Items.Add("王子");
                }
            }
            tmp1 = comboBoxCharChoose1.Text;
            if (tmp1 == "001")
            {
                comboBoxCharChoose2.Items.Remove("001"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("001");
                comboBoxCharChoose4.Items.Remove("001");

            }
            if (tmp1 == "桃太郎")
            {
                comboBoxCharChoose2.Items.Remove("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("桃太郎");
                comboBoxCharChoose4.Items.Remove("桃太郎");

            }
            if (tmp1 == "大魔王")
            {
                comboBoxCharChoose2.Items.Remove("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("大魔王");
                comboBoxCharChoose4.Items.Remove("大魔王");

            }
            if (tmp1 == "王子")
            {
                comboBoxCharChoose2.Items.Remove("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("王子");
                comboBoxCharChoose4.Items.Remove("王子");

            }

            comboBoxImageChange(pictureBoxCharChoose1, comboBoxCharChoose1.Text);
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            //圖片方塊顯示清單項目所選的圖片
            if (comboBoxCharChoose2.Text != "" && tmp2 != comboBoxCharChoose2.Text)//已經選過要把之前移除的項目加回來
            {
                if (tmp2 == "001")
                {
                    comboBoxCharChoose1.Items.Add(tmp2); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add(tmp2);
                    comboBoxCharChoose4.Items.Add(tmp2);
                }
                if (tmp2 == "桃太郎")
                {
                    comboBoxCharChoose1.Items.Add("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("桃太郎");
                    comboBoxCharChoose4.Items.Add("桃太郎");
                }
                if (tmp2 == "大魔王")
                {
                    comboBoxCharChoose1.Items.Add("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("大魔王");
                    comboBoxCharChoose4.Items.Add("大魔王");
                }
                if (tmp2 == "王子")
                {
                    comboBoxCharChoose1.Items.Add("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("王子");
                    comboBoxCharChoose4.Items.Add("王子");
                }

                comboBoxImageChange(pictureBoxCharChoose2, comboBoxCharChoose2.Text);
            }
            tmp2 = comboBoxCharChoose2.Text;
            if (tmp2 == "001")
            {
                comboBoxCharChoose1.Items.Remove("001"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("001");
                comboBoxCharChoose4.Items.Remove("001");

            }
            if (tmp2 == "桃太郎")
            {
                comboBoxCharChoose1.Items.Remove("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("桃太郎");
                comboBoxCharChoose4.Items.Remove("桃太郎");

            }
            if (tmp2 == "大魔王")
            {
                comboBoxCharChoose1.Items.Remove("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("大魔王");
                comboBoxCharChoose4.Items.Remove("大魔王");

            }
            if (tmp2 == "王子")
            {
                comboBoxCharChoose1.Items.Remove("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("王子");
                comboBoxCharChoose4.Items.Remove("王子");

            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            //圖片方塊顯示清單項目所選的圖片
            if (comboBoxCharChoose3.Text != "" && tmp3 != comboBoxCharChoose3.Text)//已經選過要把之前移除的項目加回來
            {
                if (tmp3 == "001")
                {
                    comboBoxCharChoose2.Items.Add(tmp1); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose1.Items.Add(tmp1);
                    comboBoxCharChoose4.Items.Add(tmp1);
                }
                if (tmp3 == "桃太郎")
                {
                    comboBoxCharChoose2.Items.Add("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose1.Items.Add("桃太郎");
                    comboBoxCharChoose4.Items.Add("桃太郎");
                }
                if (tmp3 == "大魔王")
                {
                    comboBoxCharChoose2.Items.Add("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose1.Items.Add("大魔王");
                    comboBoxCharChoose4.Items.Add("大魔王");
                }
                if (tmp3 == "王子")
                {
                    comboBoxCharChoose2.Items.Add("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose1.Items.Add("王子");
                    comboBoxCharChoose4.Items.Add("王子");
                }

                comboBoxImageChange(pictureBoxCharChoose3, comboBoxCharChoose3.Text);
            }
            tmp3 = comboBoxCharChoose3.Text;
            if (tmp3 == "001")
            {
                comboBoxCharChoose2.Items.Remove("001"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose1.Items.Remove("001");
                comboBoxCharChoose4.Items.Remove("001");

            }
            if (tmp3 == "桃太郎")
            {
                comboBoxCharChoose2.Items.Remove("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose1.Items.Remove("桃太郎");
                comboBoxCharChoose4.Items.Remove("桃太郎");

            }
            if (tmp3 == "大魔王")
            {
                comboBoxCharChoose2.Items.Remove("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose1.Items.Remove("大魔王");
                comboBoxCharChoose4.Items.Remove("大魔王");

            }
            if (tmp3 == "王子")
            {
                comboBoxCharChoose2.Items.Remove("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose1.Items.Remove("王子");
                comboBoxCharChoose4.Items.Remove("王子");

            }
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            //圖片方塊顯示清單項目所選的圖片
            if (comboBoxCharChoose4.Text != "" && tmp4 != comboBoxCharChoose4.Text)//已經選過要把之前移除的項目加回來
            {
                if (tmp4 == "001")
                {
                    comboBoxCharChoose2.Items.Add(tmp1); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add(tmp1);
                    comboBoxCharChoose1.Items.Add(tmp1);
                }
                if (tmp4 == "桃太郎")
                {
                    comboBoxCharChoose2.Items.Add("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("桃太郎");
                    comboBoxCharChoose1.Items.Add("桃太郎");
                }
                if (tmp4 == "大魔王")
                {
                    comboBoxCharChoose2.Items.Add("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("大魔王");
                    comboBoxCharChoose1.Items.Add("大魔王");
                }
                if (tmp4 == "王子")
                {
                    comboBoxCharChoose2.Items.Add("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                    comboBoxCharChoose3.Items.Add("王子");
                    comboBoxCharChoose1.Items.Add("王子");
                }

                comboBoxImageChange(pictureBoxCharChoose4, comboBoxCharChoose4.Text);
            }
            tmp4 = comboBoxCharChoose4.Text;
            if (tmp4 == "001")
            {
                comboBoxCharChoose2.Items.Remove("001"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("001");
                comboBoxCharChoose1.Items.Remove("001");

            }
            if (tmp4 == "桃太郎")
            {
                comboBoxCharChoose2.Items.Remove("桃太郎"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("桃太郎");
                comboBoxCharChoose1.Items.Remove("桃太郎");

            }
            if (tmp4 == "大魔王")
            {
                comboBoxCharChoose2.Items.Remove("大魔王"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("大魔王");
                comboBoxCharChoose1.Items.Remove("大魔王");

            }
            if (tmp4 == "王子")
            {
                comboBoxCharChoose2.Items.Remove("王子"); //Text = "桃太郎";//ContextMenuStrip.Text = "Text";
                comboBoxCharChoose3.Items.Remove("王子");
                comboBoxCharChoose1.Items.Remove("王子");

            }
        }

        private void comboBoxImageChange(PictureBox charImage, string charName)
        {
            switch (charName)
            {
                case "桃太郎":
                    charImage.Image = pictureBoxMapChar1.Image;
                    break;
                case "大魔王":
                    charImage.Image = pictureBoxMapChar2.Image;
                    break;
                case "001":
                    charImage.Image = pictureBoxMapChar3.Image;
                    break;
                case "王子":
                    charImage.Image = pictureBoxMapChar4.Image;
                    break;
            }
        }

        //遊戲開始 ==================================================================
        private void Gaming()
        {
        }

        private void move(int Char, int DiceNum, int mSec = 21)
        {
            DebugDice.Text = DiceNum.ToString();
            DebugDice.Refresh();

            PictureBox picBMC = pictureBoxMapChar1;
            switch (Char)
            {
                case 0: picBMC = pictureBoxMapChar1; break;
                case 1: picBMC = pictureBoxMapChar2; break;
                case 2: picBMC = pictureBoxMapChar3; break;
                case 3: picBMC = pictureBoxMapChar4; break;
            }

            for (int DNi = 0; DNi < DiceNum; DNi++)
            {
/*
                //給移動時用的列舉 ===================================================
                List<PictureBox> PicB = new List<PictureBox>();
                PicB.Add(pictureBoxGamingMap);
                PicB.Add(pictureBoxMapChar2);
                PicB.Add(pictureBoxMapChar3);
                PicB.Add(pictureBoxMapChar4);

                //移動區塊 ==========================================================
                for (int i = 0; i < mSec; i++)
                {
                    foreach (PictureBox PB in PicB)
                    {
                        PB.Left -= 210 / mSec;
                        PB.Top -= 21 / mSec;
                        PB.Refresh();
                    }
                }
*/

// 後來發現是個可有可無的一段　實際作用不明 ==============================================
                //if (panelGamingMapInside.Location.Y == -454)
                if (panelGamingMapInside.Location.Y == pGMI[0, 1])
                {
                    for (int i = 0; i < 8; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
                //if (panelGamingMapInside.Location.Y == -1342)
                if (panelGamingMapInside.Location.X == pGMI[7, 0])
                {
                    for (int i = 7; i < 14; i++)
                    {
                        if (panelGamingMapInside.Location.Y == pGMI[i, 1]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.Y == pGMI[13, 1]) //-1084
                {
                    for (int i = 13; i < 22; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.X == pGMI[21, 0])  //-523
                {
                    for (int i = 21; i < 32; i++)
                    {
                        if (panelGamingMapInside.Location.Y == pGMI[i, 1]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.Y == pGMI[31, 1]) //260
                {
                    for (int i = 31; i < 40; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.X == pGMI[39, 0])  //-1342
                {
                    for (int i = 39; i < 46; i++)
                    {
                        if (panelGamingMapInside.Location.Y == pGMI[i, 1]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.Y == pGMI[45, 1])  //-412
                {
                    for (int i = 45; i < 60; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.X == pGMI[59, 0])  //338
                {
                    for (int i = 59; i < 66; i++)
                    {
                        if (panelGamingMapInside.Location.Y == pGMI[i, 1]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.Y == pGMI[65, 1])  //260
                {
                    for (int i = 65; i < 74; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.X == pGMI[73, 0])  //-481
                {
                    for (int i = 73; i < 84; i++)
                    {
                        if (panelGamingMapInside.Location.Y == pGMI[i, 1]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.Y == pGMI[83, 1])  //-1084
                {
                    for (int i = 83; i < 92; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.X == pGMI[91, 0])  //338
                {
                    for (int i = 91; i < 98; i++)
                    {
                        if (panelGamingMapInside.Location.Y == pGMI[i, 1]) cellnum = i;
                    }
                }
                if (panelGamingMapInside.Location.Y == pGMI[97, 1])  //-454
                {
                    for (int i = 97; i < 104; i++)
                    {
                        if (panelGamingMapInside.Location.X == pGMI[i, 0]) cellnum = i;
                    }
                }
// ============================================== 後來發現是個可有可無的一段　實際作用不明

                for (int i = 0; i < mSec; i++)
                {
                    picBMC.Left += (pGMI[cellnum, 0] - pGMI[cellnum + 1, 0]) / mSec;
                    picBMC.Top  += (pGMI[cellnum, 1] - pGMI[cellnum + 1, 1]) / mSec;
                    panelGamingMapInside.Left -= (pGMI[cellnum, 0] - pGMI[cellnum + 1, 0]) / mSec;
                    panelGamingMapInside.Top  -= (pGMI[cellnum, 1] - pGMI[cellnum + 1, 1]) / mSec;
                    panelGamingMapInside.Refresh();
                    //System.Threading.Thread.Sleep(10);
                }
            }

            cellnum = (cellnum + 1) % 104;

            nextplayer();
            DebugDice.Text  = panelGamingMapInside.Left.ToString();
            DebugDice.Text += "\n";
            DebugDice.Text += panelGamingMapInside.Top.ToString();
            DebugDice.Text += "\nCN=";
            DebugDice.Text += cellnum.ToString();
        }

        private void Dice_Click(object sender, EventArgs e)
        {
            Dice_Click(sender, e, 1);
        }
        private void Dice_Click(object sender, EventArgs e, int moveTimes=1)
        {
            DebugDice.Text = charactorID.ToString();
            DebugDice.Refresh();
            move(charactorID, moveTimes);
        }

        private void pictureBoxDice_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 80; i++)
            {
                pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_1;
                pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_1;
                pictureBoxDice.Refresh();
                pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_2;
                pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_2;
                pictureBoxDice.Refresh();
                pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_3;
                pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_3;
                pictureBoxDice.Refresh();
                pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_4;
                pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_4;
                pictureBoxDice.Refresh();
                pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_5;
                pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_5;
                pictureBoxDice.Refresh();
                pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_6;
                pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_6;
                pictureBoxDice.Refresh();
            }
            Random diceRnd = new Random();
            int dicenum = diceRnd.Next(1, 6);
            switch (dicenum)
            {
                case 1:
                    pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_1;
                    pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_1;
                    break;
                case 2:
                    pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_2;
                    pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_2;
                    break;
                case 3:
                    pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_3;
                    pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_3;
                    break;
                case 4:
                    pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_4;
                    pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_4;
                    break;
                case 5:
                    pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_5;
                    pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_5;
                    break;
                case 6:
                    pictureBoxDice.Image = global::DaFuWon.Properties.Resources.dice_6;
                    pictureBoxDice.InitialImage = global::DaFuWon.Properties.Resources.dice_6;
                    break;
            }
            pictureBoxDice.Refresh();

            move(charactorID, dicenum);
        }

        private void Dice_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar > '0' && e.KeyChar <= '9')
            {
                Dice_Click(sender, new EventArgs(), e.KeyChar-'0');
            }
            else if (e.KeyChar == '0') move(charactorID, 78, 1);
        }

        private void nextplayer()
        {
            charcellnum[charactorID] = cellnum;     // 紀錄遊戲中的角色所在的新格子

            charactorID = (charactorID + 1) % 4;    // 下一位角色
            MessageBox.Show("輪到下一位玩家");
            panelGamingMapInside.Location = new System.Drawing.Point(pGMI[charcellnum[charactorID], 0], pGMI[charcellnum[charactorID], 1]);
            panelGamingMapInside.Refresh();         // 移動畫面到下一位角色所在格

            switch (charactorID)
            {
                case 0:
                    pictureBoxGamingCharStateHead.Image = global::DaFuWon.Properties.Resources.momotarou;
                    labelGamingCharStateName.Text = "桃太郎";
                    break;
                case 1:
                    pictureBoxGamingCharStateHead.Image = global::DaFuWon.Properties.Resources.ghost;
                    labelGamingCharStateName.Text = "魔王";
                    break;
                case 2:
                    pictureBoxGamingCharStateHead.Image = global::DaFuWon.Properties.Resources._001;
                    labelGamingCharStateName.Text = "001";
                    break;
                case 3:
                    pictureBoxGamingCharStateHead.Image = global::DaFuWon.Properties.Resources.king;
                    labelGamingCharStateName.Text = "王子";
                    break;
            }
        }

        private void labelZoomIn_Click(object sender, EventArgs e)
        {
            pictureBoxGamingMap.Size = new System.Drawing.Size(1794, 1484);
            pictureBoxGamingMap.Left = 0;
            pictureBoxGamingMap.Top = 0;
        }

        private void label1_Click(object sender, EventArgs e)
        {
            pictureBoxGamingMap.Size = new System.Drawing.Size(1794 / 2, 1484 / 2);
            pictureBoxGamingMap.Left = 1794 / 4;
            pictureBoxGamingMap.Top = 1484 / 4;
        }
    }
}
